<template>
	<view class="wrap" style="padding: 30rpx;">
		<view class="u-page">
			<u-time-line>
				<u-time-line-item  v-for="(formItem,index) in history.data" :key="index" nodeTop="2">
					<!-- 此处自定义了左边内容，用一个图标替代 -->
					<template v-slot:node>
						<view class="u-node" style="background: #19be6b;">
							<!-- 此处为uView的icon组件-->
							<u-icon name="account-fill" color="#fff" :size="24"></u-icon>
						</view>
					</template>
					<template v-slot:content>
						<view>
							<view class="u-order-title">{{formItem.taskName}} 
								<u-tag size="mini" style="font-size: 22rpx;margin-left:20rpx ;" :text="formItem.variables.taskBack == true ? '驳回' : '同意'" :type="formItem.variables.taskBack ? 'error' : 'success'" />
							</view>
							<view class="u-order-time">开始时间：{{formItem.startTime}}</view>
							<view class="u-order-time">结束时间：{{formItem.endTime}}</view>
							<view class="u-order-desc">审批人：{{formItem.variables.userName}}</view>
							<view class="u-order-desc">审批意见：{{formItem.comment}}</view>
						</view>
					</template>
				</u-time-line-item>
			</u-time-line>
		</view>
		<u-tabbar
			v-model="tabBar.current"  
			:list="tabBar.data" 
			@change="tabChange" 
			:inactive-color="tabBar.inactiveColor"
			:activeColor="tabBar.activeColor"
			></u-tabbar>
		
	</view>
</template>
<script>
	import request from "utils/request.js"
	export default {
		data() {
			return {
				taskInfo:{
					
				},
				history:{
					data: {
						
					}
				},
				dict:{
					user:{}
				},
				beforeHistory: "",
				tabBar:{
					inactiveColor: '#909399',
					activeColor: '#5098FF',
					data: [
						{
							iconPath: "edit-pen",
							selectedIconPath: "edit-pen",
							text: '任务',
							customIcon: false,
							
						},
						{
							iconPath: "order",
							selectedIconPath: "order",
							text: '历史',
							customIcon: false,
						},
					],
					current: 1,
				}
			}
		},
		watch:{
		  $route: {
		     handler: function(val, oldVal){
				 debugger
		       this.beforeHistory = oldVal.fullPath;
		     },
		     // 深度观察监听
		     deep: true
		   }
		},
		onLoad(data) {
			this.taskInfo = JSON.parse(data["taskInfo"])
			this.getUserList()
			this.getHistory();
		},
		methods: {
			// 历史记录
			getHistory(){
				let _this = this;
				const params = {
					taskId: this.taskInfo.taskId,
					processInstanceId: this.taskInfo.processInstanceId,
				}
				request({
					url: '/flowable/workflow/history',
					method: 'post',
					data: params
				}).then(response => {
					this.history.data = [];
					for (var i = 0; i < response.data.length; i++) {
						var curHistory = response.data[i];
						let comment = "";
						if (!curHistory.endTime) {
							curHistory.endTime = curHistory.startTime
						}
						if (!curHistory.assignee) {
							curHistory.assignee = curHistory.variables.userId
						}
						if(curHistory.variables.auditAdvice){
							comment = curHistory.variables.auditAdvice
						}else{
							if(curHistory.comment.length > 0){
								comment = curHistory.comment[0].fullMessage
							}
						}


						var detail = {
							assigner: _this.dict.user[curHistory.assignee],
							startTime: curHistory.startTime.substr(0, 19).replace("T", " "),
							endTime: curHistory.endTime.substr(0, 19).replace("T", " "),
							processInstanceId: curHistory.processInstanceId,
							taskId: curHistory.taskId,
							taskName: curHistory.taskName,
							taskFormKey: curHistory.taskFormKey,
							comment: comment,
							variables: curHistory.variables,
							processVariables : _this.taskInfo.processVariables,
							processDefinitionKey: _this.taskInfo.processDefinitionKey
						}
						_this.history.data.push(detail)
					}
					_this.history.drawer = true;
				})
			},
			//获取用户列表
			getUserList() {
				let _this = this;
				request({
					url: '/system/user/query',
					method: 'post',
				}).then(response => {
					for (var i = 0; i < response.data.length; i++) {
						_this.dict.user[response.data[i]["userId"]] = response.data[i]["userName"]
					}
				})
			},
			tabChange(current){
				if(current == 0){
					uni.navigateBack({
					    delta: 1
					});
					debugger
					// this.$u.route({
					// 	url: this.beforeHistory
					// })
				}
			}
		}
	}
</script>
<style lang="scss" scoped>
	.u-node {
		width: 44rpx;
		height: 44rpx;
		border-radius: 100rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background: #d0d0d0;
	}
	
	.u-order-title {
		color: #333333;
		font-weight: bold;
		font-size: 28rpx;
	}
	
	.u-order-desc {
		color: rgb(150, 150, 150);
		font-size: 22rpx;
		margin-bottom: 6rpx;
	}
	
	.u-order-time {
		color: rgb(200, 200, 200);
		font-size: 22rpx;
	}
</style>
